<template>
    <view>
       <!-- <dataTable :thList="thList" :flag="isflag" :colWidthList="colWidthList" thBgColor="#0096D3" thColor="#fff" thSize="30"
            thHeight="70" borderColor="	White" :tbList="tbData">
        </dataTable> -->
		<dataTable :thList="thList" :isflag="isflag" :colWidthList="colWidthList" :thBgColor="fontcolor.color" thColor="#fff" thSize="30"
		    thHeight="70" :borderColor="fontcolor.color" :tbList="tbData">
		</dataTable>
		<prompt :visible.sync="promptVisible" :flag="flag" :title="title" style="z-index: 1;" placeholder="输入请设置滚动间隔时间" :isMutipleLine="isMutipleLine" :defaultValue="time"
			@confirm="clickPromptConfirm" :mainColor="fontcolor.color">
		</prompt>
    </view>
</template>

<script>
	import dataTable from '../../components/lun-dataTable/lun-dataTable.vue'
	import Prompt from '../../components/zz-prompt/index.vue';
	export default {
		components: {
			dataTable,
			Prompt,
		},
		data() {
			return {
				fontcolor:{
				color:this.$kdup.color,
				borderBottom:'2px solid '+this.$kdup.color
				},
				bj:{
				backgroundColor:this.$kdup.color,
				},
				color:this.$kdup.color,
				isflag:"2",
				flag:"2",
				time:"10",
				title:"设置间隔时间（秒）",
				isMutipleLine: true, //是否开启大文本
				promptVisible: false, //是否关闭弹出款
				thList: ['工序单号','生产订单号', '产品编码', '产品名称', '规格型号','排班','员工', '机台号', '汇报开始时间','汇报结束时间', '计划数','领料数'
				,'工序','完成比例','完成率','合计数','汇报合格数','不合格数', '报废数'
				],
				colWidthList: [300,300,300,400,300,200,200,200,350,350,200,200,
				200,200,200,200,200,200,200],
				tbData:[],
				pagesize:10,
				pagecur:0,
				timer:null,
				tbList: []
			}
		},
		onUnload() {
		if(this.timer) {  
				clearTimeout(this.timer);  
				this.timer = null;  
			}
		},
		//注销
		onNavigationBarButtonTap (e){  
		if(e.text=="滚动间隔时间"){
		this.promptVisible = true;
		} 
		},
		onHide() {
		if(this.timer) {  
				clearTimeout(this.timer);  
				this.timer = null;  
			}
		},
		onLoad() {
			var str="/*dialect*/select gx.FBILLNO,gx1.FSCDJBILLNO 订单号,m.FNUMBER 产品编码 "+
			" ,m1.FNAME 产品名称,m1.FSPECIFICATION 规格型号, CASE gx1.FDUTYWORK WHEN 'A' THEN '白班' WHEN 'B' THEN '夜班'  ELSE '' END  as 排班,em.FNAME,jl.FNAME,substring( convert(varchar,s.FDATE,120),1,20) 汇报开始时间, "+
			" substring( convert(varchar,s.FDATE,120),1,20) 汇报结束时间,Convert(decimal(18,0),gx1.FQTY) 计划数量 "+
			" ,Convert(decimal(18,0),q.FPICKMTLQTY) 领料数,gxl.FNAME 工序,cast(Convert(decimal(18,0),s.FGXQTY) as varchar(20))+'/'+cast(Convert(decimal(18,0),gx1.FQTY) as varchar(20))  完成比例,Convert(decimal(18,0),s.FGXQTY/gx1.FQTY*100) 完成率,Convert(decimal(18,0),s.FGXQTY+s.FFAILQTY+s.FBADQTY) 汇报合计数,Convert(decimal(18,0),s.FGXQTY) 汇报数, "+
			" Convert(decimal(18,0),s.FFAILQTY) 不合格数,Convert(decimal(18,0),s.FBADQTY) 报废数 "+
			" from  top_t_HBGX gx inner join top_t_HBGXEntry  gx1 on gx.FID=gx1.FID inner join T_BD_MATERIAL m "+
			" on m.FMATERIALID=gx1.FMATERIALID inner join T_BD_MATERIAL_L m1 on m1.FMATERIALID=m.FMATERIALID inner join "+
			" T_PRD_MOENTRY mo on mo.F_KDUP_TEXT=gx1.FSCDJBILLNO inner join  T_PRD_MOENTRY_Q q on mo.FENTRYID=q.FENTRYID "+
			"  inner join top_t_HBGXSubEntry s on gx1.FEntryID=s.FEntryID left join KDUP_t_JTSJ_L jl on gx1.F_TOP_JTBH=jl.FID"+
			"  left join T_HR_EMPINFO_L em on em.fid=gx1.FEMPLOYEE  inner join top_t_GXXL_L gxl on gxl.FID=s.FGXXL  order by gx.FBILLNO"
			var data={sql:str}
			this.$myRequest.postRequest("LoadListJson", data).then(res => {
				if (this.$kdup.isEmpty(res.data.error)) {
					//res.data.Table.pop();
					for (let item of res.data.Table) {
					var arr = Object.keys(item).map(function(i){return item[i]});
						this.tbList.push(arr);
					}
					this.initData();
				} else {
					uni.showToast({
						title: res.data.error,
						icon: "none"
					});
				}
			})
        },
		onShow() {
			uni.setNavigationBarColor({
				frontColor: "#ffffff",	//文字颜色
				backgroundColor: this.$kdup.color	//底部背景色
			})
		},
		methods: {
			initData(){
			this.init()
			this.timer = setInterval(() => { 
			this.Inter();	
			}, (this.time*1000))	
			},
			init(){
				//获取每页的数据
				for(var i=this.pagecur;i<this.pagesize;i++){
					if(this.tbList[i]==undefined){
						break;
					}else{
					this.tbData.push(this.tbList[i]);	
					}
				}
				//处理每页报表显示的格式
				var arrformat=[];
				for(var i=0;i<this.tbData.length;i++){
					if(i!=(this.tbData.length-1)){
						if(this.tbData[i][0]==this.tbData[i+1][0]){
							 arrformat.push(i+1);
						}
					}
				}
	            for(var i=0;i<this.tbData.length;i++){
					for(var j=0;j<arrformat.length;j++){
						if(i==arrformat[j]){
						this.tbData[i][0]="";
						this.tbData[i][1]="";
						this.tbData[i][2]="";
						this.tbData[i][3]="";
						this.tbData[i][4]="";
						}
					}	
				}
			},
			Inter(){
			 	this.pagecur+=10;
				this.pagesize+=10;
				if((this.tbList.length-this.pagecur)<=0){
					 this.pagecur=0;
					 this.pagesize=10;
				}
				this.tbData=[];
				this.init();
			},
			clickPromptConfirm(val) {
		    this.time=val;
			uni.showToast({
				icon: 'none',
				title: '滚动间隔时间是：'+this.time+'秒',
				duration: 2000
			});
			if(this.timer) {
				clearTimeout(this.timer);  
				this.timer = null;  
			}
			this.initData();
			},
		}
	}
</script>

<style>

</style>
